`
https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown/
`

/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
  const n = prices.length
  const dp = Array.from({ length: n }, () => new Array(2).fill(0))

  for (let i = 0; i < n; i++) {
    // 处理边界
    if (i - 1 === -1) {
      dp[i][0] = 0
      dp[i][1] = -prices[i]
      continue
    }
    if (i - 2 === -1) {
      dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] + prices[i])
      dp[i][1] = Math.max(dp[i - 1][1], -prices[i])
      continue
    }
    // 休息或卖出
    dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] + prices[i])
    // 休息或买入，有冷静期，要从两天前的算起
    dp[i][1] = Math.max(dp[i - 1][1], dp[i - 2][0] - prices[i])
  }

  return dp[n - 1][0]
};